<?php
class kst_return_gudang_model extends MY_Model {
	var $model = 'kst_return_gudang_model';

function getApp1()
{
		$ls_sql	=  "SELECT	SUPPLIER_ID value,
							SUPPLIER_NAMA display
					FROM	ADMIN_PRIMKOKAS.KM_SUPPLIER
					ORDER BY SUPPLIER_NAMA";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
}

	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	*
					FROM	pro_tagihan_listrik
					WHERE	(UPPER(no_tagihan_listrik) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(nama_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_tenant) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan) LIKE '%".strtoupper(post('keyword'))."%') 
							ORDER BY ".(post('sort')=='' ? 'no_tagihan_listrik' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode($this->paging($ls_sql) );

	}
		
	function Add($arr_data){
		$this->db->insert('pro_tagihan_listrik', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_tagihan_listrik', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_no_tagihan_listrik){
		$result = $this->db->get_where('pro_tagihan_listrik', array('no_tagihan_listrik' => $as_no_tagihan_listrik));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_no_tagihan_listrik)
	{
		$result = $this->db->get_where('pro_tagihan_listrik', array('no_tagihan_listrik' => $as_no_tagihan_listrik));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_tagihan_listrik WHERE no_tagihan_listrik = '".$arr_rule['no_tagihan_listrik']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['no_tagihan_listrik']."]<br />";
			}else{
				$this->db->delete('pro_tagihan_listrik', array('no_tagihan_listrik' => $arr_rule['no_tagihan_listrik']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>